package com.example.ffepeg.ffeAdder;

import java.io.IOException;

//获取第一帧图片
public class FFdoyiziDate {
    public static void main(String[] args) {
        // 视频文件路径
       // String inputVideoPath = "https://pushimg.liecaizhijia.com/video/gen/2024-09-24/89a32ab1-3657-4e56-a83f-bda21593f817.mp4";
        String inputVideoPath = "https://pushimg.liecaizhijia.com/adminshop/20250320/f085b0abb2251dcab4356b28037782dd.mp4";
        // 输出图片路径
        String outputImagePath = "src/main/resources/file/outImageMp4002.png";

        // FFmpeg命令
        String[] cmd = {
                "ffmpeg",
                "-i", inputVideoPath,
                "-vf", "select=eq(n\\,0)", // 选择第0帧
                "-vframes", "1",
                "-q:v", "2",
                outputImagePath
        };

        try {
            // 执行命令
            Process process = new ProcessBuilder(cmd).start();
            int exitCode = process.waitFor();
            System.out.println("Command executed with exit code: " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

}
